Skip to content

Conversation

Lagoja
Copy link
Contributor

@Lagoja Lagoja commented Sep 24, 2024

Summary

Users can set the port that process-compose runs on when they use devbox services. If they do not specify a port, we default to randomly picking an open port with low risk of conflict

Users can specify their process-compose port by:

  1. Passing the --pcport, -p flag when running devbox services up.
  2. Setting the PC_PORT_NUM environment variable. This variable can be set in the projects devbox.json if you want to always use the same port for process-compose. This is overridden by the --pcport flag.

How was it tested?

In the MySQL example:

  1. When I run devbox services up -b -p 8080, or
  2. When I run PC_PORT_NUM devbox services up -b,

I can verify that process-compose is running on my 8080 with curl localhost:8080/processes and seeing the list of expected processes.

@Lagoja Lagoja requested a review from mikeland73 September 24, 2024 22:56
BinPath string
ExtraFlags []string
Background bool
PCPort int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProcesssComposePort

return configPort, nil
}

if portStr, exists := os.LookupEnv("PC_PORT_NUM"); exists {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on naming this DEVBOX_PC_PORT_NUM

Reasons:

  • If user sets PC_PORT_NUM outside of devbox, it's going to make starting devbox services on multiple projects fail. Since this is the env name set by process compose itself, it's not unreasonable that people will set it.
  • Keeping track of env variables is easier if we prefix them
  • Avoids collisions

return port > 1024 && disallowedPorts[port] == ""
}

func isPortAvailable(port int) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make getAvailablePort call this.

if port <= 0 {
return 0, fmt.Errorf("invalid PC_PORT_NUM environment variable: ports cannot be less than 0")
}
return port, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return port, isPortAvailable(port) so you don't have to call it outside.

Comment on lines 137 to 138
if !isPortAvailable(port) {
return fmt.Errorf("port %d is already in use", port)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove, call inside selectPort

@Lagoja Lagoja merged commit 68edd30 into main Sep 25, 2024
26 checks passed
@Lagoja Lagoja deleted the jl/pc-port branch September 25, 2024 22:44
Copy link

sentry-io bot commented Sep 27, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ **net.DNSError: <redacted *errors.withStack>: <redacted errors.withStack>: <redacted net.DNSError> go.jetpack.io/devbox/internal/services in getAv... View Issue
  • ‼️ **syscall.Errno: <redacted errors.withStack>: <redacted fs.PathError>: go.jetpack.io/devbox/internal/shellgen in Write... View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants